package cn.iocoder.yudao.module.water.controller.admin.day1;

import cn.iocoder.yudao.module.water.controller.admin.month.vo.NDayReqVO;
import cn.iocoder.yudao.module.water.controller.admin.month.vo.ReportMonthRespVO;
import cn.iocoder.yudao.module.water.convert.month.ReportMonthConvert;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.water.controller.admin.day1.vo.*;
import cn.iocoder.yudao.module.water.dal.dataobject.day1.ReportDay1DO;
import cn.iocoder.yudao.module.water.convert.day1.ReportDay1Convert;
import cn.iocoder.yudao.module.water.service.day1.ReportDay1Service;

@Api(tags = "管理后台 - 日报表1")
@RestController
@RequestMapping("/water/report-day1")
@Validated
public class ReportDay1Controller {

    @Resource
    private ReportDay1Service reportDay1Service;

    @PostMapping("/create")
    @ApiOperation("创建日报表1")
    @PreAuthorize("@ss.hasPermission('water:report-day1:create')")
    public CommonResult<Long> createReportDay1(@Valid @RequestBody ReportDay1CreateReqVO createReqVO) {
        return success(reportDay1Service.createReportDay1(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新日报表1")
    @PreAuthorize("@ss.hasPermission('water:report-day1:update')")
    public CommonResult<Boolean> updateReportDay1(@Valid @RequestBody ReportDay1UpdateReqVO updateReqVO) {
        reportDay1Service.updateReportDay1(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除日报表1")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('water:report-day1:delete')")
    public CommonResult<Boolean> deleteReportDay1(@RequestParam("id") Long id) {
        reportDay1Service.deleteReportDay1(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得日报表1")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
    @PreAuthorize("@ss.hasPermission('water:report-day1:query')")
    public CommonResult<ReportDay1RespVO> getReportDay1(@RequestParam("id") Long id) {
        ReportDay1DO reportDay1 = reportDay1Service.getReportDay1(id);
        return success(ReportDay1Convert.INSTANCE.convert(reportDay1));
    }

    @GetMapping("/list")
    @ApiOperation("获得日报表1列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
    @PreAuthorize("@ss.hasPermission('water:report-day1:query')")
    public CommonResult<List<ReportDay1RespVO>> getReportDay1List(@RequestParam("ids") Collection<Long> ids) {
        List<ReportDay1DO> list = reportDay1Service.getReportDay1List(ids);
        return success(ReportDay1Convert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得日报表1分页")
    @PreAuthorize("@ss.hasPermission('water:report-day1:query')")
    public CommonResult<PageResult<ReportDay1RespVO>> getReportDay1Page(@Valid ReportDay1PageReqVO pageVO) {
        PageResult<ReportDay1DO> pageResult = reportDay1Service.getReportDay1Page(pageVO);
        return success(ReportDay1Convert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出日报表1 Excel")
    @PreAuthorize("@ss.hasPermission('water:report-day1:export')")
    @OperateLog(type = EXPORT)
    public void exportReportDay1Excel(@Valid ReportDay1ExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ReportDay1DO> list = reportDay1Service.getReportDay1List(exportReqVO);
        // 导出 Excel
        List<ReportDay1ExcelVO> datas = ReportDay1Convert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "日报表1.xls", "数据", ReportDay1ExcelVO.class, datas);
    }

    @GetMapping("/get-one-day-report")
    @ApiOperation("获得一日日报")
    @ApiImplicitParam(name = "date", value = "时间", required = true, example = "1024", dataTypeClass = Date.class)
    @PreAuthorize("@ss.hasPermission('water:report-day1:query')")
    public CommonResult<List<ReportDay1DO>> getReportMonth(@RequestParam("date") String date) {
        List list = reportDay1Service.getReportOneDay1List(date);
        return success(ReportDay1Convert.INSTANCE.convertList(list));
    }

    @PostMapping("/get-n-day-report")
    @ApiOperation("获得N日日报")
    @PreAuthorize("@ss.hasPermission('water:report-day1:query')")
    public CommonResult<List<ReportDay1DO>> getReportNDay1List(@Valid @RequestBody NDayReqVO vo) {
        List list = reportDay1Service.getReportNDay1List(vo.getStartTime(),vo.getEndTime());
        return success(ReportDay1Convert.INSTANCE.convertList(list));
    }

}
